//
//  CollHerad.m
//  card
//
//  Created by 韦显光 on 2017/4/21.
//  Copyright © 2017年 xg韦. All rights reserved.
//

#import "CollHerad.h"
#import "UIButton+WebCache.h"
#import "MenuColl.h"
#import "SDCycleScrollView.h"
#import "LSMarqueeView.h"
@interface CollHerad ()<SDCycleScrollViewDelegate>
{
      MenuColl*menuColl;
      SDCycleScrollView *cycleScrollView;
      NSArray*zdata;
}
@property (weak, nonatomic) IBOutlet UIView *Bannerback;
@property (weak, nonatomic) IBOutlet UIView *MenuBack;
@property (weak, nonatomic) IBOutlet UIView *Msgback;
@property (nonatomic, strong) LSMarqueeView *marqueeView;

@end
@implementation CollHerad

-(void)CellInitfor:(NSDictionary*)dic
{
    if (!menuColl) {
        menuColl=[MenuColl instanceCenterViewWithType];
        menuColl.frame=CGRectMake(0, 0, DEVW, 100);
        [menuColl Cellinit:nil];
        [_MenuBack addSubview:menuColl];
        cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, DEVW, 150) delegate:self placeholderImage:WXGImage(@"")];
        
        [FuncPublic getData:nil parameters:nil RequestUrl:@"http://pai.aimeichuang.cn/Api/System/banner" success:^(NSDictionary *acountInfo) {
       
            NSMutableArray*mary=[NSMutableArray array];
           NSArray*tempary= acountInfo[@"result"][@"list"];
            [tempary enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                NSDictionary*dic=obj;
                [mary addObject:dic[@"img_url"]];
                
            }];
             cycleScrollView.imageURLStringsGroup =mary;
            
            [self runzlb];
        }];

       
        [_Bannerback addSubview:cycleScrollView];
      

    }

}


/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    
}

-(void)runzlb
{
    [FuncPublic getData:nil parameters:nil RequestUrl:@"http://pai.aimeichuang.cn/Api/System/toutiao" success:^(NSDictionary *acountInfo) {
        zdata=acountInfo[@"result"][@"list"];
        
        NSMutableArray *tempArr = @[].mutableCopy;
        [zdata enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            UILabel *labelOne = [UILabel new];
            labelOne.font = [UIFont systemFontOfSize:14];
            //        labelOne.tag=[zdata[idx][@"id"] integerValue];
            NSString*temp1=WXGStr(zdata[idx][@"nickname"]);
            NSString*str1=[NSString stringWithFormat:@"%@ 拍得 %@",temp1,zdata[idx][@"goods_name"]];
            NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:str1];
            [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,temp1.length)];
            [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica" size:12.0] range:NSMakeRange(temp1.length, str1.length-temp1.length)];
              [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica" size:15.0] range:NSMakeRange(0,temp1.length)];
            labelOne.attributedText=str;
            [tempArr addObject:labelOne];
        }];
        
        // >>>>>> dataSorce >>>>>
        
        if (!self.marqueeView) {
            self.marqueeView = [[LSMarqueeView alloc] initWithFrame:CGRectMake(0, 0, DEVW-90, 40)];
            self.marqueeView.lsLabelArr = tempArr;
            [self.marqueeView beginShowAdd];
            [_Msgback addSubview:self.marqueeView];
            self.marqueeView.clickBlock = ^(UILabel*sender){
                
            };
            
        }
        
    }];

}
- (IBAction)btna:(UIButton *)sender {
    self.completion(sender);
    
}


@end
